var oTable =null;

// -------------------------------- Phan quan ly thong ke thuc vat------------------------------------------------
function viewAllThucVat(){
	$.ajax({
		type : "POST",
		url : "/culaocham/getData.doo",
		data: {name: "datatableThucVat"},
		cache : false,
		dataType : "json",
		success : function(dataTable) {
			setInfoDatatableTV(dataTable);
	},
	error : function(e) {
		alert('Error ' + e);
	}
	});
	$("#thucVatDialog").dialog("open");
}

// chon loai thuc vat de xem thong tin
$(document).ready(function() {
	$('#selectedLoaiTV .thucvatLoai').remove();
	
    $('#selectLoaiTV .thucvatLoai').live('click', function () { 
        $(this).appendTo("#selectedLoaiTV");
    });

    $('#selectedLoaiTV .thucvatLoai').live('click', function () { 
        $(this).appendTo("#selectLoaiTV");
    });
});

function viewSelectThucVat(){
	var arraySelectTV = [];
	var selectIndexTV = document.getElementById("selectedLoaiTV");
	for(var i = 0; i< selectIndexTV.length; i++){
		arraySelectTV.push(selectIndexTV[i].value);
	} 
	if(arraySelectTV.length != 0){
		$.ajax({
			type : "POST",
			url : "/culaocham/getData.doo",
			data: {name: "datatableSelectTV", arraySelectTV : JSON.stringify(arraySelectTV)},
			cache : false,
			dataType : "json",
			success : function(dataTable) {
				setInfoDatatableTV(dataTable);
		},
		error : function(e) {
			alert('Error ' + e);
		}
		});
		$("#thucVatDialog").dialog("open");
	}
}

function setInfoDatatableTV(dataTable){
	if(oTable!=null) oTable.fnDestroy();
	oTable = $("#thucVatList").dataTable({
		"sDom": 'T<"clear">lfrtip',
		"aoColumns": [
		              { "sWidth": "5%" },
		              { "sWidth": "10%" },
		              { "sWidth": "10%" },
		              { "sWidth": "7%" },
		              { "sWidth": "10%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "15%" },
		              { "sWidth": "5%" },
		              { "sWidth": "25%" },
		              { "sWidth": "10%" },
		          ],
         "aaData": dataTable["datatableThucVat"], // them du lieu vao cho datatable
         "oTableTools": {
             "aButtons": [
                 {
                     "sExtends":    "xls",
                     "sButtonText": "Excel"
                 },
                 {
                     "sExtends":    "pdf",
                     "sButtonText": "PDF"
                 },
                 {
                     "sExtends":    "print",
                     "sButtonText": "Print"
                 }
             ]
         },
         "bSort": false
	});
}

//-------------------------------- Phan quan ly thong ke dong vat------------------------------------------------
function viewAllDongVat(){
	$.ajax({
		type : "POST",
		url : "/culaocham/getData.doo",
		data: {name: "datatableDongVat"},
		cache : false,
		dataType : "json",
		success : function(dataTable) {
			setInfoDatatableDV(dataTable);
	},
	error : function(e) {
		alert('Error ' + e);
	}
	});
	$("#dongVatDialog").dialog("open");
}

// chon loai dong vat de xem thong tin
$(document).ready(function() {
	$('#selectedLoaiDV .dongvatLoai').remove();
	
    $('#selectLoaiDV .dongvatLoai').live('click', function () { 
        $(this).appendTo("#selectedLoaiDV");
    });

    $('#selectedLoaiDV .dongvatLoai').live('click', function () { 
        $(this).appendTo("#selectLoaiDV");
    });
});

function viewSelectDongVat(){
	var arraySelectDV = [];
	var selectIndexDV = document.getElementById("selectedLoaiDV");
	for(var i = 0; i< selectIndexDV.length; i++){
		arraySelectDV.push(selectIndexDV[i].value);
	} 
	if(arraySelectDV.length != 0){
		$.ajax({
			type : "POST",
			url : "/culaocham/getData.doo",
			data: {name: "datatableSelectDV", arraySelectDV : JSON.stringify(arraySelectDV)},
			cache : false,
			dataType : "json",
			success : function(dataTable) {
				setInfoDatatableDV(dataTable);
		},
		error : function(e) {
			alert('Error ' + e);
		}
		});
		$("#dongVatDialog").dialog("open");
	}
}

function setInfoDatatableDV(dataTable){
	if(oTable!=null) oTable.fnDestroy();
	oTable = $("#dongVatList").dataTable({
		"sDom": 'T<"clear">lfrtip',
		"aoColumns": [
		              { "sWidth": "3%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "14%" },
		              { "sWidth": "16%" },
		              { "sWidth": "28%" },
		              { "sWidth": "10%" },
		          ],
         "aaData": dataTable["datatableDongVat"], // them du lieu vao cho datatable
         "oTableTools": {
             "aButtons": [
                 {
                     "sExtends":    "xls",
                     "sButtonText": "Excel"
                 },
                 {
                     "sExtends":    "pdf",
                     "sButtonText": "PDF"
                 },
                 {
                     "sExtends":    "print",
                     "sButtonText": "Print"
                 }
             ]
         },
         "bSort": false
	});
}
//-----------------------------------------------------Phan quan ly thong ke sinh vat------------------------------------
var oTableSVTV = null;
var oTableSVDV = null;
function setInfoDatatableSV(dataTable){
	if(oTableSVTV!=null) oTableSVTV.fnDestroy();
	oTableSVTV = $("#thucVatPolygon").dataTable({
		"sDom": 'T<"clear">lfrtip',
		"aoColumns": [
		              { "sWidth": "5%" },
		              { "sWidth": "10%" },
		              { "sWidth": "10%" },
		              { "sWidth": "7%" },
		              { "sWidth": "10%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "15%" },
		              { "sWidth": "5%" },
		              { "sWidth": "25%" },
		              { "sWidth": "10%" },
		          ],
         "aaData": dataTable["datatableThucVat"], // them du lieu vao cho datatable
         "oTableTools": {
             "aButtons": [
                 {
                     "sExtends":    "xls",
                     "sButtonText": "Excel"
                 },
                 {
                     "sExtends":    "pdf",
                     "sButtonText": "PDF"
                 },
                 {
                     "sExtends":    "print",
                     "sButtonText": "Print"
                 }
             ]
         },
         "bSort": false
	});
	
	if(oTableSVDV!=null) oTableSVDV.fnDestroy();
	oTableSVDV = $("#dongVatPolygon").dataTable({
		"sDom": 'T<"clear">lfrtip',
		"aoColumns": [
		              { "sWidth": "3%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "7%" },
		              { "sWidth": "14%" },
		              { "sWidth": "16%" },
		              { "sWidth": "28%" },
		              { "sWidth": "10%" },
		          ],
         "aaData": dataTable["datatableDongVat"], // them du lieu vao cho datatable
         "oTableTools": {
             "aButtons": [
                 {
                     "sExtends":    "xls",
                     "sButtonText": "Excel"
                 },
                 {
                     "sExtends":    "pdf",
                     "sButtonText": "PDF"
                 },
                 {
                     "sExtends":    "print",
                     "sButtonText": "Print"
                 }
             ]
         },
         "bSort": false
	});
}
